package com.gdth.bank.presenter;

import android.widget.Toast;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import com.gdth.bank.BankApplication;
import com.gdth.bank.event.MessageEvent;
import com.gdth.bank.model.TAppCanshuModel;
import com.gdth.widget.dialog.BaseToast;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONException;
import org.json.JSONObject;

public class TAppCanshuPresenter {
	private TAppCanshuModel mTAppCanshuModel;
	
	public TAppCanshuPresenter() {
		mTAppCanshuModel = new TAppCanshuModel();
	}
	
	/**
	 * 根据类型获取参数
	 * @param
	 */
	public void getCanshuOnline() {
		mTAppCanshuModel.getCanshuOnline()
		.subscribeOn(Schedulers.io())
		.unsubscribeOn(Schedulers.io())
		.observeOn(Schedulers.io())
		.subscribe(new Subscriber<String>(){

			@Override
			public void onCompleted() {
				// TODO Auto-generated method stub
			}

			@Override
			public void onError(Throwable arg0) {
				// TODO Auto-generated method stub
				BaseToast.getInstance().ShowCenterToast(BankApplication.mInstance.getBaseContext(), "获取参数失败："+arg0.getMessage());
			}

			@Override
			public void onNext(String arg0) {
				// TODO Auto-generated method stub
				mTAppCanshuModel.saveCanshuCache(arg0);
			}
		});
	}
	// 获取绩效总工资
	public void  getjxgzhz(String zh){
		JSONObject val=new JSONObject();

		try {
			val.put("zh" ,zh);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		mTAppCanshuModel.getjxgzhz(val.toString())
				.subscribeOn(Schedulers.io())
				.unsubscribeOn(Schedulers.io())
				.observeOn(Schedulers.io())
				.subscribe(new Subscriber<String>(){

					@Override
					public void onCompleted() {
						// TODO Auto-generated method stub
					}

					@Override
					public void onError(Throwable arg0) {
						// TODO Auto-generated method stub
						BaseToast.getInstance().ShowCenterToast(BankApplication.mInstance.getBaseContext(), "获取参数失败："+arg0.getMessage());
					}

					@Override
					public void onNext(String arg0) {
						// TODO Auto-generated method stub
						//mTAppCanshuModel.saveCanshuCache(arg0);
						EventBus.getDefault().post(new MessageEvent(MessageEvent.SHOW_ALL_MONEY,String.valueOf(arg0)));
					}
				});

	}
}
